home *** CD-ROM | disk | FTP | other *** search
- /*
- File: LinkList.h
-
- Contains: Primitive linked list class
-
- Owned by: Richard Rodseth and Jens Alfke
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 5/24/96 jpa 1.1MRD: pragma internal eliminates NOPs.
- Also inlined methods.
-
- In Progress:
-
- */
-
- #ifndef _LINKLIST_
- #define _LINKLIST_
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
-
- #ifdef PRAGMA_INTERNAL_SUPPORTED
- #pragma internal on
- #endif
-
- //=====================================================================================
- // Theory of Operation
- //=====================================================================================
-
- /*
-
- Note: These classes are private to the implementation. They are not available
- to part handlers.
-
- Note: These are primitive classes for implementing higher-level collections
- For example, to create a FrameList class, subclass Link to add a field to
- store the frame. The FrameList class would use a LinkedList in its implementation
- and would manufacture the Link objects internally.
-
- */
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- //==============================================================================
- // Scalar Types
- //==============================================================================
-
- //==============================================================================
- // Classes defined in this interface
- //==============================================================================
-
- class Link;
- class LinkedList;
- class LinkedListIterator;
-
- //==============================================================================
- // Classes used by this interface
- //==============================================================================
-
-
- //==============================================================================
- // Link
- //==============================================================================
-
- class Link {
- public:
-
- Link();
-
- Link(Link* next, Link* previous);
-
- Link( const Link& );
-
- virtual ~Link();
-
- Link* GetNext() const {return fNext;}
-
- Link* GetPrevious() const {return fPrevious;}
-
- // The following operations are provided for efficiency, but DO NOT USE THEM
- // if there are any iterators active on a list. These operations don't bump
- // the list's fSeed and the iterators will not be able to detect that they
- // are out of sync!
-
- void Remove( );
-
- void AddBefore( Link *aLink );
-
- void AddAfter( Link *aLink );
-
- //private-by-convention:
-
- void SetNext(Link* aLink) {fNext = aLink;}
-
- void SetPrevious(Link* aLink) {fPrevious = aLink;}
-
- private:
-
- Link* fNext;
- Link* fPrevious;
- };
-
-
- //==============================================================================
- // LinkedList
- //==============================================================================
-
-
- class LinkedList {
-
- public:
-
- LinkedList();
-
- ~LinkedList() { }
-
- ODBoolean IsEmpty( ) const;
-
- ODULong Count() const;
-
- ODBoolean Includes( const Link* ) const;
-
- void Remove(Link&);
-
- void RemoveAll();
-
- void DeleteAllLinks();
-
- Link* RemoveFirst();
-
- Link* RemoveLast();
-
- void AddBefore(Link& existing, Link* link);
-
- void AddAfter(Link& existing, Link* link);
-
- void AddFirst(Link* link);
-
- void AddLast(Link* link);
-
- void AddLast( LinkedList &list );
-
- void AddLastUnique( LinkedList &list );
-
- Link* After(const Link& link) const;
-
- Link* Before(const Link& link) const;
-
- Link* First() const;
-
- Link* Last() const;
-
- protected:
-
- Link fSentinel; // Marks the head & tail
- ODULong fSeed; // Used to detect out-of-sync iterators
-
- Link* GetSentinel( )
- {return &fSentinel;}
- const Link* GetSentinel( ) const
- {return &fSentinel;}
- ODBoolean IsSentinel( const Link* link ) const
- {return link==this->GetSentinel();}
- ODBoolean NotSentinel( const Link* link ) const
- {return link!=this->GetSentinel();}
-
- private:
- friend class LinkedListIterator;
- };
-
-
- //=====================================================================================
- // LinkedListIterator
- //=====================================================================================
-
- class LinkedListIterator {
-
- public:
-
- LinkedListIterator(LinkedList* list);
-
- ~LinkedListIterator() { }
-
- Link* First();
-
- Link* Next();
-
- Link* Last();
-
- Link* Previous();
-
- Link* Current() {return fCurrent;}
-
- ODBoolean IsNotComplete() {return (fCurrent != kODNULL);}
-
- void RemoveCurrent();
-
- private:
-
- LinkedList* fList;
- Link* fCurrent;
- Link* fNext; // Used only when deleting while iterating
- Link* fPrevious; // Used only when deleting while iterating
- Link* fSentinel;
- ODULong fSeed; // Used to detect out-of-sync iterators
-
- };
-
-
- #ifdef PRAGMA_INTERNAL_SUPPORTED
- #pragma internal off
- #endif
-
- #endif // _LINKLIST_